/*
 * GreenZombie.cpp
 *
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses 
 */

#include "GreenZombie.h"
#include "MovStrategyFactory.h"
#include "ModelConstants.h"

GreenZombie::GreenZombie(int x, int y)
    : Enemy(x, y) {
    init();
}

GreenZombie::GreenZombie(int id, int x, int y)
    : Enemy(id, x, y) {
    init();
}

void GreenZombie::init() {
    Properties properties = Properties();
    resistance = properties.getPropertyAsInt("enemy_resistance");
    speed = properties.getPropertyAsInt("enemy_speed");
    mov_strategy = MovStrategyFactory::createMovementStrategy(ZOMBIE_GREEN, this);
    range = properties.getPropertyAsInt("g_zombie_range");
    points = properties.getPropertyAsInt("g_zombie_points");
    direction = NO_DIRECTION;
}

int GreenZombie::scoutForBomberman(Map& map) {
    int bomberman_direction = NO_DIRECTION;
    if (scoutDirection(map, direction)) {
        bomberman_direction = direction;
    } else if (scoutDirection(map, direction*-1)) {
        bomberman_direction = direction*-1;
    }
    return bomberman_direction;
}

void GreenZombie::determineMovementDirection(Map& map) {
    int horizontal_count = 0;
    int vertical_count = 0;
    if (! map.tileIsOccupied(x-1, y)) {
        horizontal_count++;
    }
    if (! map.tileIsOccupied(x+1, y)) {
        horizontal_count++;
    }
    if (! map.tileIsOccupied(x, y-1)) {
        vertical_count++;
    }
    if (! map.tileIsOccupied(x, y+1)) {
        vertical_count++;
    }
    if (vertical_count > horizontal_count) {
        direction = UP;
    } else {
        direction = RIGHT;
    }
}

GreenZombie* GreenZombie::clone() {
    GreenZombie* clone = new GreenZombie(*this);
    clone->mov_strategy = MovStrategyFactory::createMovementStrategy(ZOMBIE_GREEN, clone);
    return clone;
}

ModelObject GreenZombie::getRepresentation() {
    return ZOMBIE_GREEN;
}
